﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using RedisDemos.Extensions;
using RedisDemos.Scenarios;

namespace RedisDemos
{
    class Program
    {
        static void Main(string[] args)
        {
            TaskScheduler.UnobservedTaskException += (s, e) =>
            {
                var rootEx = e.Exception.Flatten().GetBaseException();
                var msg = rootEx.GetType().Name + ": " + rootEx.Message;
                msg.LogError();
            };

            try
            {
                Scenarios().ForEach(s => s.Execute().Wait());
                "Done!".LogInfo();
            }
            catch (AggregateException aex)
            {
                var rootEx = aex.Flatten().GetBaseException();
                var msg = rootEx.GetType().Name + ": " + rootEx.Message;
                msg.LogError();
            }
        }

        private static IEnumerable<Scenario> Scenarios()
        {
            yield return new Cache();
            yield return new DistributeLock();
            yield return new DistributeLockTran();
            yield return new UserRegistrationAndProfile();
            yield return new OnlineUsers();
            yield return new OnlineUsersRem();
            yield return new ActiveUsers();
            yield return new UserAgents();
            yield return new Timelines();
            yield return new Tagging();
            yield return new JobQueues();
            yield return new CustomIncrement();
            yield return new LiveDiagnostic();
            yield return new Autocomplete();
        }
    }
}
